class Solution {
public:
    int singleNumber(int A[], int n) {
        unsigned int *a=(unsigned int *)&A[0];
        unsigned int zero=0xffffffff, one=0, two=0;
        for (int i=0;i<n;i++) {
            one=(one^(one&a[i])) | (zero&a[i]);
            zero=(zero^(zero&a[i])) | (two&a[i]);
            two=0xffffffff^zero^one;
        }
        return one;
    }
};
